Optimal Sampling Strategies in Quicksort and Quickselect

نویسندگان

  • Conrado Martínez
  • Salvador Roura
چکیده

It is well known that the performance of quicksort can be improved by selecting the median of a sample of elements as the pivot of each partitioning stage. For large samples the partitions are better, but the amount of additional comparisons and exchanges to find the median of the sample also increases. We show in this paper that the optimal sample size to minimize the average total cost of quicksort, as a function of the size n of the current subarray size, is a ·√n+ o(√n ). We give a closed expression for a, which depends on the selection algorithm and the costs of elementary comparisons and exchanges. Moreover, we show that selecting the medians of the samples as pivots is not the best strategy when exchanges are much more expensive than comparisons. We also apply the same ideas and techniques to the analysis of quickselect and get similar results.

برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

منابع مشابه

Partitioning schemes for quicksort and quickselect

We introduce several modifications of the partitioning schemes used in Hoare’s quicksort and quickselect algorithms, including ternary schemes which identify keys less or greater than the pivot. We give estimates for the numbers of swaps made by each scheme. Our computational experiments indicate that ternary schemes allow quickselect to identify all keys equal to the selected key at little add...

متن کامل

Chunksort: A Generalized Partial Sorting Algorithm

We introduce here the problem of generalized partial sorting and chunksort, an algorithm closely related to quicksort and quickselect that solves this problem in an elegant and efficient way. In generalized partial sorting we are given an array of n elements and p intervals I1 = [`1,u1], I2 = [`2,u2], . . . , Ip = [`p,up], which define p blocks in the array and p+1 gaps between the blocks. The ...

متن کامل

The Number of Symbol Comparisons in QuickSort and QuickSelect

We revisit the classical QuickSort and QuickSelect algorithms, under a complexity model that fully takes into account the elementary comparisons between symbols composing the records to be processed. Our probabilistic models belong to a broad category of information sources that encompasses memoryless (i.e., independent-symbols) and Markov sources, as well as many unbounded-correlation sources....

متن کامل

Moves and displacements of particular elements in Quicksort

In this research note we investigate the number of moves and the displacement of particular elements during the execution of the well-known quicksort algorithm. This type of analysis is useful if the costs of data moves were dependent on the source and target locations, and possibly the moved element itself. From the mathematical point of view, the analysis of these quantities turns out to be r...

متن کامل

ذخیره در منابع من


  با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید

برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

عنوان ژورنال:
  • SIAM J. Comput.

دوره 31  شماره 

صفحات  -

تاریخ انتشار 2001